package com.asia5b.a5mall.middleware.model.member

import android.text.TextUtils
import com.asia5b.a5bmall.resource.ResString
import com.asia5b.a5mall.middleware.R
import com.asia5b.a5mall.middleware.model.base.BaseModel
import com.asia5b.a5mall.middleware.utils.WTimeUtils
import com.google.gson.annotations.SerializedName
import java.io.Serializable
import java.util.*

/**
 * Created by zhangyuncai on 2019/12/21.
 * @Note   用户信息Model
 * @param  username 用户名
 * @param  nikename 昵称
 * @param  buyPoint 消费积分
 * @param  levelPoint 等级积分
 * @param  face 头像
 * @param  sex 性别
 * @param  birthday 生日
 * @param  pro 省份
 * @param  proId 省份ID
 * @param  city 城市
 * @param  cityId 城市ID
 * @param  county 县级
 * @param  countyId 县级ID
 * @param  town 乡村
 * @param  townId 乡村ID
 * @param  address 详细地址
 * @param  email 电子邮件
 * @param  tel 固话
 */
class MemberModel : BaseModel() {


    @SerializedName(value = "username", alternate = ["uname"])
    var username = ""


    @SerializedName(value = "nikename", alternate = ["nickname"])
    var nikename = ""


    @SerializedName(value = "buyPoint", alternate = ["consum_point"])
    val buyPoint = 0

    @SerializedName(value = "levelPoint", alternate = ["grade_point"])
    val levelPoint = 0
    var face: String = ""

    var sex = 0
    var birthday = 0L

    @SerializedName(value = "pro", alternate = ["province"])
    var pro = ""


    @SerializedName(value = "proId", alternate = ["province_id"])
    var proId = 0
    var city = ""


    @SerializedName(value = "cityId", alternate = ["city_id"])
    var cityId = 0
    var county = ""


    @SerializedName(value = "countyId", alternate = ["county_id"])
    var countyId = 0
    var town = ""


    @SerializedName(value = "townId", alternate = ["town_id"])
    var townId = 0
    var address = ""

    var email = ""

    var mobile = ""

    var tel = ""

    var member_id = 0
    var open_id = ""



    fun getSexString(): String {
        if (sex == 1) {
            return ResString.get(R.string.男)
        } else {
            return ResString.get(R.string.女)
        }
    }

    fun getRegionId(): Int {

        if (townId != null && townId!! > 0) {
            return townId!!
        }

        if (countyId != null && countyId!! > 0) {
            return countyId!!
        }

        return 0

    }

    fun getBirthdayString(): String {
        if (birthday != null) {
            return WTimeUtils.toString(Date(birthday!!), null)
        } else {
            return ""
        }
    }

    fun getRegion(): String {
        return "$pro$city$county$town"
    }

    var gr = ""

    var shop_id = 0
    var have_shop = ""//1:表示该用户已经有店铺了

    fun haveShop(): Boolean {
        return TextUtils.equals(have_shop, "1") && shop_id > 0
    }
}

/*
{
    "member_id": 169,
    "uname": "m_15889636926",
    "email": "1107241393@qq.com",
    "create_time": 1575884082,
    "sex": 0,
    "birthday": 1577515802000,
    "province_id": 53112,
    "city_id": 55675,
    "county_id": 56108,
    "town_id": 0,
    "province": "马来西亚（Malaysia）",
    "city": "Pahang",
    "county": "Benta",
    "town": "",
    "address": "天河大道2号",
    "mobile": "15889636926",
    "tel": "020-87654321",
    "grade_point": 25,
    "consum_point": 25,
    "msn": null,
    "remark": null,
    "last_login": 1579190998,
    "login_count": 90,
    "is_cheked": null,
    "recommend_point_state": null,
    "info_full": 1,
    "find_code": null,
    "face": "http:\/\/47.88.173.86:82\/testShopImg\/20191231\/DDA9D29421534
    "midentity": null,
    "disabled": 0,
    "shop_id": null,
    "have_shop": 0,
    "nickname": "张运才2",
    "gr": "60",
    "mch_user_code": null
}
 */